#ifndef __LUA_TEST_ENTRY_H__
#define __LUA_TEST_ENTRY_H__

#include "cm_os.h"

/**
 * @brief Starts the Lua test task.
 *
 * This function creates a new RTOS task dedicated to running the Lua VM
 * and executing the test scripts.
 */
void lua_test_entry_start(void);

typedef enum {
    LUA_EVENT_TIMER,
    LUA_EVENT_NET_REG_STATUS,
    LUA_EVENT_MQTT_CONNACK,
    LUA_EVENT_MQTT_DISCONNECTED,
    LUA_EVENT_MQTT_MESSAGE,
    LUA_EVENT_UART_RX,
    LUA_EVENT_NTP_SYNC_RESULT,
    LUA_EVENT_HTTP_RSP_DATA,
    LUA_EVENT_HTTP_RSP_DONE,
    LUA_EVENT_HTTP_RSP_ERROR,
    LUA_EVENT_HTTP_PROGRESS,
} lua_event_id_t;

/**
 * @brief NTP sync result structure for event queue
 */
typedef struct {
    int is_ok;
    char *time_str;
} ntp_result_t;

typedef struct {
    int client_ref; // Reference to the lua_http_client userdata
    int status_code; // For DONE and ERROR
    char *data; // For DATA chunk or error message
    size_t data_len; // For DATA chunk
    size_t total_len; // For PROGRESS
    size_t received_len; // For PROGRESS
} http_event_data_t;

/**
 * @brief Lua event structure
 */
typedef struct {
    lua_event_id_t id;
    union {
        int ival;
        void *pval;
    } data;
} lua_event_t;

/**
 * @brief Post an event to the Lua task queue
 *
 * @param event Pointer to the event structure
 * @return osStatus_t
 */
osStatus_t lua_event_post(const lua_event_t *event);

#endif // __LUA_TEST_ENTRY_H__
